package com.smile.controller;

import cn.hutool.core.bean.BeanUtil;
import com.smile.commons.page.R;
import com.smile.model.dto.request.*;
import com.smile.model.request.*;
import com.smile.service.LiveService;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/live")
public class LiveController {

    @Autowired
    private LiveService liveService;

    /**
     * 设置直播镜头
     *
     * @param liveLensChangeRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/liveLensChange")
    public R<Void> liveLensChange(@RequestBody LiveLensChangeRequest liveLensChangeRequest) throws MqttException {
        liveService.liveLensChange(BeanUtil.copyProperties(liveLensChangeRequest, LiveLensChangeRequestDTO.class));

        return R.ok();
    }

    /**
     * 直播相机切换
     *
     * @param liveCameraChangeRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/liveCameraChange")
    public R<Void> liveCameraChange(@RequestBody LiveCameraChangeRequest liveCameraChangeRequest) throws MqttException {
        liveService.liveCameraChange(BeanUtil.copyProperties(liveCameraChangeRequest, LiveCameraChangeRequestDTO.class));
        return R.ok();
    }

    /**
     * 设置直播清晰度
     *
     * @param liveSetQualityRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/liveSetQuality")
    public R<Void> liveSetQuality(@RequestBody LiveSetQualityRequest liveSetQualityRequest) throws MqttException {
        liveService.liveSetQuality(BeanUtil.copyProperties(liveSetQualityRequest, LiveSetQualityRequestDTO.class));
        return R.ok();
    }

    @PostMapping("/speakerPlayModeSet")
    public R<Void> speakerPlayModeSet() {
        return R.ok();
    }

    /**
     * 开启直播
     *
     * @return
     * @throws MqttException
     */
    @PostMapping("/liveStartPush")
    public R<Void> liveStartPush(@RequestBody LiveStartPushRequest liveStartPushRequest) throws MqttException {
        liveService.liveStartPush(BeanUtil.copyProperties(liveStartPushRequest, LiveStartPushRequestDTO.class));
        return R.ok();
    }

    /**
     * 关闭直播
     *
     * @return
     * @throws MqttException
     */
    @PostMapping("/liveStopPush")
    public R<Void> liveStopPush(@RequestBody LiveStopPushRequest liveStopPushRequest) throws MqttException {
        liveService.liveStopPush(BeanUtil.copyProperties(liveStopPushRequest, LiveStopPushRequestDTO.class));
        return R.ok();
    }
}
